package cn.itcast.bos.before.service.impl;

import java.util.Date;
import java.util.UUID;

import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

import cn.itcast.bos.before.service.OrderService;
import cn.itcast.bos.domain.base.Area;
import cn.itcast.bos.domain.delivery.Order;
import cn.itcast.crm.domain.Customer;

@Service
public class OrderServiceImpl implements OrderService{

	@Override
	public void addOrder(Order t, String sendMobileMsg, String sendAreaInfo,
			String recAreaInfo) {
		// TODO Auto-generated method stub
		String orderNum = UUID.randomUUID().toString();
		t.setOrderNum(orderNum);
		t.setStatus("1");
		t.setOrderTime(new Date());
		//获取用户
		Customer customer=(Customer) ServletActionContext.getRequest().
		getSession().getAttribute("customer");
		//存储客户ID到订单
		System.out.println(customer.getId());
		t.setCustomer_id(customer.getId());
		//获取发件地址区域
		String[] address1 = sendAreaInfo.split("/");
		Area sendarea = WebClient.create("http://localhost:8080/bos_management/bos_mgr/bos/area").query("address", address1).
		accept(MediaType.APPLICATION_JSON).get(Area.class);
		System.out.println(sendarea);
		t.setSendArea(sendarea);
		//获取寄件区域
		String[] adderss2 = recAreaInfo.split("/");
		Area recarea = WebClient.create("http://localhost:8080/bos_management/bos_mgr/bos/area").query("address", adderss2).
				accept(MediaType.APPLICATION_JSON).get(Area.class);
		System.out.println(recarea);
		t.setRecArea(recarea);
		//获取快递员
		String fixedAreaId = customer.getFixedAreaId();
		System.out.println(t);
		WebClient.create("http://localhost:8080/bos_management/bos_mgr/bos/order")
		.type(MediaType.APPLICATION_JSON).post(t);
//		--------------------------------------------------------------------------------------
	
		
	}



}
